package org.testis.gui.mvc.controller.testdesign;

import org.testis.gui.mvc.controller.*;
import org.testis.gui.mvc.model.testdesign.LabelPairSettingsModel;
import org.testis.orm.labelhandler.LabelHandlerFactory;
import java.util.HashMap;

import org.testis.orm.refinedclasses.TestDesignTreeNode;

/**
 *
 * @author nurhat
 */
public class LabelPairSettingsController extends AbstractController {

    public static final String SELECTED_NODE_PROPERTY = "SelectedNode";
    public static final String ERROR_PROPERTY = "LastError";
    public static final String LABELS_PROPERTY = "LabelHashMap";
    private TestDesignTreeNode m_selectedNode;

    public LabelPairSettingsController() {
        super();
        initialize();
    }

    public void operationEditSettings(TestDesignTreeNode node) {
        HashMap labels = LabelHandlerFactory.getInstance(node).getLabelsAsHashMap(
                node, false);
        operationSetSelectedNode(node);
        operationSetLabels(labels);
    }

    public void operationNewSettings() {
        operationSetSelectedNode(null);
        operationSetLabels(new HashMap());
    }

    public void operationSetSelectedNode(TestDesignTreeNode node) {
        m_selectedNode = node;
        setModelProperty(SELECTED_NODE_PROPERTY, node);
    }

    public void operationSetLabels(HashMap labels) {
        setModelProperty(LABELS_PROPERTY, labels);
    }

    public TestDesignTreeNode getSelectedNode() {
        return m_selectedNode;
    }

    private void initialize() {
        addModel(new LabelPairSettingsModel());
    }
}
